import { RoleBase } from "../Item/Role/RoleBase";
import { GameCache } from "./GlobalContext";

export default class GameInfo{
    private static _instance: GameInfo = null;
    static get inst(): GameInfo { 
        if(this._instance == null){
            this._instance = new GameInfo();
        }
        return this._instance; 
    }

    private _level: number = 0;
    get level(){
        return this._level;
    }
    set level(val: number){
        this._level = val;
    }

    gameCache: Array<Array<RoleBase>> = [
        [],
        []
    ];

    gameStart(){
        this.level = 0;
        this.init();
    }

    init(){
        this.gameCache = [
            [],
            []
        ];
        for(let i = 0; i < 42; i++){
            this.gameCache[0][i] = null;
            this.gameCache[1][i] = null;
        }
    }

    updateChace(role: RoleBase, index: number, type: GameCache){
        if(role.index != -1){
            GameInfo.inst.gameCache[type][role.index] = null;
            role.index = -1;
        }
        this.gameCache[type][index] = role;
    }
}